package com.example.viewtest.ActivityGroup;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.example.viewtest.AdapterGroup.ListViewAdapter;
import com.example.viewtest.Dao.Bean;
import com.example.viewtest.R;
import com.example.viewtest.Tools.BaseActivity;

import java.util.ArrayList;
import java.util.List;

public class ListViewMain extends BaseActivity {

    private List<Bean> list = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview_main);
        initData();
        ListView textView = this.findViewById(R.id.list_view);
        textView.setAdapter(new ListViewAdapter(list,ListViewMain.this));
        textView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ListViewMain.this,"你点击了："+position,Toast.LENGTH_SHORT).show();
            }
        });
        textView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ListViewMain.this,"你长按了："+position,Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }

    public void initData(){
        for (int i=0;i<30;i++){
            Bean bean = new Bean();
            bean.setName("大宝" + i);
            list.add(bean);
        }
    }
}
